package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hopu.blb_erp.entity.*;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.service.IOrder2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author A-Zhang
 * @since 2021-11-18
 */
@Api
@Controller
@RestController
public class Order2Controller {
    @Autowired
    private IOrder2Service order2Service;
    @ApiOperation("分页查询")
    @GetMapping("/order2s/{current}/{pageSize}")
    public ResponseEntity<PageEntity<Order2>> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize){
        PageEntity<Order2> orderPage = order2Service.findPage(current, pageSize);
        return ResponseEntity.ok(orderPage);
    }
    //更新数据
    @PutMapping("/order2s")
    public ResponseEntity<String> modifyMenu(@RequestBody Order2 order2){
//        Order2 byId = order2Service.getById(order2.getId());
//        byId.setProductId(order2.getProductId());
        order2Service.saveOrUpdate(order2);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("查询需要交移仓库的订单")
    @GetMapping("/order2s")
    public ResponseEntity<List<Order2>> findOrdersToHandover(){
        List<Order2> order2List = order2Service.list(Wrappers.<Order2>lambdaQuery().eq(Order2::getProductStatus,3));
        return ResponseEntity.ok(order2List);
    }

    @ApiOperation("查询添加到交移单的订单")
    @GetMapping("/order2/{id}")
    public ResponseEntity<Order2> findOrderById(@PathVariable("id") String id ){
        return ResponseEntity.ok(order2Service.getById(id));
    }
    @ApiOperation("查询订单加模糊查询加分页")
    @GetMapping("/orders/list/{start}/{pageSize}")
    public ResponseEntity<PageEntity<Order2ToBeProduced>> findOrderPage(@PathVariable("start") Integer start, @PathVariable("pageSize") Integer pageSize, String orderId, String dealTime){
        PageEntity<Order2ToBeProduced> page = order2Service.findPage(start, pageSize, orderId, dealTime);
        System.out.println(page);
        return ResponseEntity.ok(page);
    }
    @ApiOperation("添加订单")
    @PostMapping("/order2")
    public ResponseEntity<String> addOrder(@RequestBody Order2 order){
        order.setOrderStatus("0");
        order2Service.save(order);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("更新订单")
    @PutMapping("/order2")
    public ResponseEntity<String> modifyOrder(@RequestBody Order2 order){
        order2Service.saveOrUpdate(order);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("分页查询激光码")
    @GetMapping("/Order2s/page")
    public ResponseEntity<PageEntityP<Order2>> findPage(@RequestParam(value = "current",defaultValue = "1")
                                                       Integer current){
        PageEntityP<Order2> page = order2Service.findPPage(current);
        return ResponseEntity.ok(page);
    }
    @ApiOperation("更改激光码")
    @PutMapping("/Order2/{id}")
    public ResponseEntity<String> modifyOrder2(@PathVariable("id") String orderId){
        order2Service.modifyOrder2(orderId);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("更改祖码")
    @PutMapping("/Order2_zumaid/{orderId}")
    public ResponseEntity<String> addZumaid(@PathVariable("orderId") String orderId){
        String zumaId = LocalDateTime.now().toString().replace("-", "").replace("T", "").replace(":", "").replace(".", "");
        order2Service.modifyZumaid(orderId,zumaId);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("批量删除激光码")
    @DeleteMapping("/Order2s/{ids}")
    public ResponseEntity<String>removeOrder2(@PathVariable("ids") List<Integer> ids){
        order2Service.removeOrder2(ids);
        return ResponseEntity.ok("ok");
    }
    @ApiOperation("根据订单编号查询激光码")
    @GetMapping("/Order2zb/{orderId}")
    public ResponseEntity<List<Order2>> findOrder2ByOrderId(@PathVariable("orderId") String orderId){
        Order2 byId = order2Service.findOrder2ByOrderId(orderId);
        System.out.println(byId );
        List<Order2> Order2s = new ArrayList<>();
        Order2s.add(byId);
        return ResponseEntity.ok(Order2s);
    }
//

}
